/*
 * @Author: 码上talk|RC
 * @Date: 2020-06-09 23:23:29
 * @LastEditTime: 2021-10-04 11:35:33
 * @LastEditors: 码上talk|RC
 * @Description:
 * @FilePath: /ma-portal/store/sys/actions.js
 * @Just do what I think it is right
 */

import * as types from './mutation-types';
import { model } from '@/model';
import { localStorage } from '@/utils/localStorage';

const { Request } = model;

export const actions = {
  getLatestVersion ({ commit }) {
    const request = new Request();
    request.do('open', 'sys', 'appVersion', { params: { type: 3, version: 'latest' }, data: {} }).then(res => {
      const { status, data } = res;
      if (status) {
        const { version, isEnd } = data;
        const lcv = localStorage.getLocalVersion();
        if (!isEnd) {
          commit(types.SET_WS_UPDATE_IS_WILL_UPDATE, true);
        }
        if (!lcv || localStorage.getLocalVersion() !== version) {
          commit(types.SET_WS_UPDATE_IS_SHOW_UPDATE_LOG, true);
          localStorage.setLocalVersion(version);
        }
        commit(types.SET_WS_UPDATE_VERSION, data);
      }
    });
  }
};
